/**
 * 
 */
package com.oscarmovie.dao;

import java.util.List;

import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.oscarmovie.model.Suggestion;

/**
 * @author zhengda
 *
 */
public class SuggestionDaoImpl extends HibernateDaoSupport implements SuggestionDao {

	/* (non-Javadoc)
	 * @see com.oscarmovie.dao.SuggestionDao#save(com.oscarmovie.model.Suggestion)
	 */
	
	public void save(Suggestion suggestion) {
		getSession().saveOrUpdate(suggestion);
	}

	/* (non-Javadoc)
	 * @see com.oscarmovie.dao.SuggestionDao#load(int)
	 */
	
	public Suggestion load(int id) {
		Suggestion suggestion = (Suggestion)getSession().load(Suggestion.class, id);
		return suggestion;
	}
	
	public void delete(int id){
		Suggestion sg = new Suggestion();
		sg.setId(id);
		getSession().delete(sg);
	}

	/* (non-Javadoc)
	 * @see com.oscarmovie.dao.SuggestionDao#loadAll()
	 */
	@SuppressWarnings("unchecked")
	
	public List<Suggestion> loadAll() {
		Query query = getSession().createQuery("from Suggestion suggestion");
		query.setCacheable(true);
		List<Suggestion> list = (List<Suggestion>)query.list();
		return list;
	}

}
